// Copyright [2020] <unknown>
#include <bits/stdc++.h>
using namespace std;
// #define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
#define dbg(x...) { cerr << "\033[32;1m" << #x << " -> "; err(x); }
void err() { cerr << "\033[39;0m" << endl; }
template<typename T, typename... A>
void err(T a, A... x) { cerr << a << ' '; err(x...); }
#else
#define dbg(...)
#endif

#define sz(x) ((int)x.size())

typedef long long LL;

const int N = 1e5+50;
pair<int, pair<int, int>> a[N];
int n, t;


int vis[N];

void go(int lab) {
    for (int cur=-1, i=0; i<n; i++) {
        if (a[i].first < cur || vis[a[i].second.second])
            continue;
        // if (lab == 2)
        //     dbg(i, cur, a[i].first, vis[i], a[i].second.first, a[i].second.second);
        cur = a[i].second.first;
        vis[a[i].second.second] = lab;
    }
}

int main(int argc, char const *argv[]) {

    // code
    scanf("%d", &t);
    for (int kk=0; kk<t; ++kk) {
        scanf("%d", &n);
        memset(vis, 0, 4 * n);
        for (int i=0; i<n; ++i) {
            scanf("%d%d", &a[i].first, &a[i].second.first);
            a[i].second.second = i;
        }
        sort(a, a+n);

        go(1);
        go(2);
        printf("Case #%d: ", kk+1);
        bool suc = true;
        for (int i=0; i<n; ++i) {
            if (vis[i] == 0) {
                puts("IMPOSSIBLE");
                suc = false;
                break;
            }
        }
        // for (int i=0; i<n; ++i)
        //     dbg(i, vis[i]);

        if (!suc)
            continue;
        for (int i=0; i<n; ++i) {
            if (vis[i] == 1)
                putchar('C');
            else
                putchar('J');
        }
        putchar('\n');
    }
    return 0;
}
